package com.wframe.project.jnd.wx.controller;

import com.frame.database.JdataBean;
import com.frame.database.PageResult;
import com.wframe.project.jnd.entity.UiFloor;
import com.wframe.project.jnd.rest.util.JsonReturn;
import com.wframe.project.jnd.rest.util.WebSession;
import com.wframe.project.jnd.services.*;
import com.wframe.project.jnd.util.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by Administrator on 2017/4/14.
 */
@Controller
public class WeIndexController {

    @Autowired
    UserService userService;

    @Autowired
    OrderService orderService;

    @Autowired
    InformationService informationService;

    @Autowired
    ProductService productService;

    @Autowired
    UiFloorService uiFloorService;

    @RequestMapping(value = "we/index")
    public String home(HttpSession session, Model model) throws Exception {

        Long userIdVal = null;
        if (WebSession.checkLoginStatus(session)) {
            String userid = WebSession.getWbUser(session).getUserid();
            model.addAttribute("user", userService.getUser(userid).getDataMap());
            model.addAttribute("ordernum", orderService.statStatusNum(userid));
            model.addAttribute("usernum", userService.statUserPro(userid, UserService.UserSourceEnum.WECHAT.ordinal()).getDataMap());
            if (userid != null && userid.trim().matches("^\\d{1,10}$")) {
                userIdVal = Long.valueOf(userid.trim());
            }
        }
        List<UiFloor> uiFloors = this.uiFloorService.getFloorByPlatform(UiFloor.Platform.WE, userIdVal);
        model.addAttribute("uiFloors", uiFloors);

        JdataBean parm = new JdataBean();
        parm.put("code", "003101");
        model.addAttribute("banners", informationService.queryInfos(parm, 5, 1).getList());//加载首页滚动广告图
        return "/wesite/view/index";
    }

}
